﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BillingSystem
{
    /// <summary> Диалог редактирования клиентской информации </summary>
    public partial class FormEditClient : Form, IDialog
    {
        public FormEditClient()
        {
            InitializeComponent();
        }

        /// <summary> Показ диалога </summary>
        /// <param name="bs"></param>
        /// <returns></returns>
        public bool ShowForm(BindingSource bs)
        {
            DataRowView drv = (DataRowView)bs.Current;

            if (drv.IsNew)
            {
                drv["CLIENT_ID"] = 0;
                drv["ACCOUNT_NUMBER"] = 0;
                drv["MONEY"] = 0;
                drv["FIO"] = "";
                drv["ADDRESS"] = "";
                drv["PASSPORT"] = 0;
                this.Text = "Добавление нового клиента";
            }
            else
            {
                this.Text = "Редактирование клиентской информации";
            }

            this.textBoxAddress.DataBindings.Add("Text", drv, "ADDRESS", false,
                DataSourceUpdateMode.OnValidation);
            this.textBoxFIO.DataBindings.Add("Text", drv, "FIO", false,
                DataSourceUpdateMode.OnValidation);
            this.textBoxPassport.DataBindings.Add("Text", drv, "PASSPORT", false,
                DataSourceUpdateMode.OnValidation, null, "N0");

            if (this.ShowDialog() == DialogResult.OK)
            {
                if (textBoxFIO.Text == null)
                {
                    drv.CancelEdit();
                    return false;
                }
                drv.EndEdit();
                return true;
            }
            else
            {
                drv.CancelEdit();
                return false;
            }
        }
    }
}
